<!DOCTYPE html>
<html lang="zh-CN">
<head>
    {include file="public/static" /}
</head>
<body>
<div class="layui-form" style="margin: 0 auto; width: 900px;">
    <div class="layui-form">
        <table class="layui-table">
            <thead>
                <tr>
                  <th>数据库名称</th>
                  <th>卷数</th>
                  <th>压缩</th>
                  <th>数据大小</th>
                  <th>备份时间</th>
                  <th>状态</th>
                  <th>操作</th>
                </tr> 
            </thead>
            <tbody>
                {foreach name='list' item='data'}   
                <tr>
                  <td>{$data.time|date='Ymd-His',###}</td>
                  <td>{$data.part}</td>
                  <td>{$data.compress}</td>
                  <td>{$data.size|format_bytes}</td>
                  <td>{$key}</td>
                  <td class="status">-</td>
                  <td class="action">
                     <a class="db-down" href="{:url('Backdata/down',['time'=>$data['time']])}">下载</a>&nbsp;
                      <a class="db-import" href="{:url('Backdata/import',['time'=>$data['time']])}">还原</a>&nbsp;
                      <a class="ajax-get confirm" href="{:url('Backdata/del',['time'=>$data['time']])}">删除</a>
                  </td>
                </tr>
                {/foreach}
          </tbody>
        </table>
    </div>
</div>

<script>
layui.use(['jquery','layer'],function(){
    window.$ = layui.$;
    var layer = layui.layer;
    $(".db-import").click(function(){
        var self = this, status = ".";
        $(this).parent().prevAll('.status').html("").html('等待还原');
        $.get(self.href, success, "json");
        window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
        return false;
        function success(data){
            if(data.code==1){
                $(self).parent().prev().text(data.msg);
                if(data.data.part){
                    $.get(self.href, 
                        {"part" : data.data.part, "start" : data.data.start}, 
                        success, 
                        "json"
                    );
                    
                }  else {
                    layer.alert(data.msg);
                    //window.onbeforeunload = function(){ return null; }
                }
            } else {
                layer.alert(data.msg);
            }
        }
    });
});
</script>
</body>
</html>